import React, { useEffect, useState } from "react";
import '../../appcommon.css';
import styles from './transfer.module.css';
import { useDispatch } from "react-redux";
import { DotLoading, Mask } from "antd-mobile";
import { saveEvent } from "@/store/actions/saveEvent";
import { useHistory } from "react-router-dom/cjs/react-router-dom.min";


import NavigateBar from "@/components/NavigateBar";
import { getTransferResultInfo } from "@/utils/storage";
import { LangEn } from "@/utils/langEn";

/**
 * 登录页
 */
export default function TransferResult() {

    //loading状态
    const [maskVisible, setMaskVisible] = useState(false)

    //显示add home弹框
    const [addHomeMaskVisible, setAddHomeMaskVisible] = useState(false);
    const [addHomeMaskIsHomeMode, setAddHomeMaskIsHomeMode] = useState(true);

    // 当前 信息
    const [curResultInfo, setCurResultInfo] = useState({})

    // 文案翻译
    const [curLang, setCurLang] = useState(LangEn);

    // 获取 Redux 分发器
    const dispatch = useDispatch()

    //router
    const history = useHistory()

    //清空登录信息
    useEffect(() => {
        //关闭loading
        setMaskVisible(false);

        // 获取账号信息
        let transferResultInfo = getTransferResultInfo();
        setCurResultInfo(transferResultInfo);

        //打点
        doHitEvent("TRANSFER_RESULT_START")

        return () => {
            //打点
            doHitEvent("TRANSFER_RESULT_END")
        }
    }, [])

    // 点击 next
    const onHandleSubmit = () => {
        console.log('点击确定');

        // 返回
        history.goBack();
    };


    //打点接口
    const doHitEvent = async (type, remark = "") => {
        console.log("doHitEvent: " + type + " , " + remark);

        try {
            //获取Action
            const action = saveEvent(type, remark)

            //触发接口
            await dispatch(action)

        } catch (e) {
            console.log(e)
        }
    }


    return (
        <div className='pageRoot pageBackgroundColorGray'>
            <NavigateBar theme="white" showLogout={false} onAddFavorite={() => { setAddHomeMaskIsHomeMode(false); setAddHomeMaskVisible(true) }} onAddHome={() => { setAddHomeMaskIsHomeMode(true); setAddHomeMaskVisible(true) }}>{curLang.transferTransfer}</NavigateBar>

            {/* 使用添加 home screen bar */}
            {/* <AddFavorite onAddHome={() => { setAddHomeMaskIsHomeMode(true); setAddHomeMaskVisible(true) }} /> */}

            <div className="pageContentColumnFullPaddingHorizontal16px">
                {/* To */}
                <div className={styles.transferResultAmount}>{curResultInfo.amount} {curResultInfo.unit}</div>

                <div className={styles.transferResultMenuContent}>
                    <div className={styles.transferResultMenuRow}>
                        <div className={styles.transferResultMenuTitle}>{curLang.transferResultDate}</div>
                        <div className={styles.transferResultMenuValue}>{curResultInfo.date}</div>
                    </div>

                    <div className={styles.transferResultMenuRow}>
                        <div className={styles.transferResultMenuTitle}>{curLang.transferResultStatus}</div>
                        <div className={styles.transferResultMenuValue}>{curLang.transferResultProcessing}</div>
                    </div>

                    <div className={styles.transferResultMenuRow}>
                        <div className={styles.transferResultMenuTitle}>{curLang.transferResultReceiver}</div>
                        <div className={styles.transferResultMenuValue}>{curResultInfo.address}</div>
                    </div>
                </div>

                {/* 提交 */}
                <div className="pageBtnSubmit pageMarginTop26px" onClick={onHandleSubmit}>{curLang.transferResultOK}</div>
            </div>

            {/* 底部 margin */}
            <div className="pageBottomEdge"></div>

            {/* load mask */}
            <Mask visible={maskVisible} opacity={0.1}
                onMaskClick={() => { }}>
                <div className="pageLoadingOverlayContent">
                    <span style={{ fontSize: 24, color: '#3498DB' }} >
                        <DotLoading color="currentColor" />
                    </span>
                </div>
            </Mask>
        </div >
    )
}